package com.baizhi.service.impl;

import com.baizhi.dao.GroupDAO;
import com.baizhi.dao.TagDAO;
import com.baizhi.entity.Class;
import com.baizhi.entity.Group;
import com.baizhi.entity.Tag;
import com.baizhi.service.GroupService;
import com.baizhi.util.MybatisUtil;

import java.util.List;

public class GroupServiceImpl implements GroupService {
    @Override  //查询所有小组
    public List<Group> queryAll() {
        List<Group> list = null;
        try {

            GroupDAO gd = (GroupDAO) MybatisUtil.getMapper(GroupDAO.class);
            list = gd.selectAll();
            MybatisUtil.commit();

        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();  //向上回滚
            throw new RuntimeException(e);
        }finally {
            MybatisUtil.close();  //关闭资源
        }
        return list;
    }

    @Override  //删除一条数据
    public void deleteById(int id) {

        try {

            GroupDAO gd = (GroupDAO) MybatisUtil.getMapper(GroupDAO.class);
            gd.deleteById(id);
            MybatisUtil.commit();
        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();  //向上回滚
            throw new RuntimeException(e);

        }finally {
            MybatisUtil.close();  //关闭资源
        }
    }

    @Override  //插入一条数据
    public void insertGroup(Group group) {

        try{

            GroupDAO gd = (GroupDAO) MybatisUtil.getMapper(GroupDAO.class);
            gd.insertGroup(group);
            MybatisUtil.commit();
        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();  //向上回滚
            throw new RuntimeException(e);
        }finally {
            MybatisUtil.close();  //关闭资源
        }
    }


/* //查询所有班级 */
    @Override
    public List<Class> selectGroupClass() {

        List<Class> list = null;
        try {

            GroupDAO gd = (GroupDAO) MybatisUtil.getMapper(GroupDAO.class);
            list = gd.queryGroupClass();
            MybatisUtil.commit();

        }catch (Exception e){
            e.printStackTrace();
            MybatisUtil.rollback();  //向上回滚
            throw new RuntimeException(e);
        }finally {
            MybatisUtil.close();  //关闭资源
        }
        return list;
    }
}
